﻿using System;
using System.Text;

namespace Util.QueryParser.Token
{
    class Literal : IToken       //Case sensitive string
    {
        private readonly string str;

        public Literal(string str)
        {
            if (str.Length < 2 || str[0] != '"' || str[str.Length - 1] != '"' || str[str.Length - 2] == '\\')
            {
                throw new ArgumentException("Error in parameter str");
            }

            this.str = str.Substring(1, str.Length - 2);
        }

        public bool Evaluate(string value)
        {
            return System.Text.RegularExpressions.Regex.Match(value, str).Success;
        }
    }
}
